﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;

namespace FlashlightRecorder.ViewModels
{
    public interface IDisposableHost : IDisposable
    {
        void AddDisposable(IDisposable item);
    }

    public class DisposableHost : IDisposableHost
    {
        List<IDisposable> items = new List<IDisposable>();

        public void AddDisposable(IDisposable item)
        {
            items.Add(item);
        }

        public void Dispose()
        {
            items.ForEach(x =>
            {
                try
                {
                    x.Dispose();
                }
                catch (Exception)
                {
                }

            });
        }
    }
    internal static class DisposableHostHelper
    {
        public static void RegisterDispose(this IDisposable item, IDisposableHost target)
        {

            target.AddDisposable(item);
        }
    }
}
